package com.atguigu.gmall.task.scheduled;

import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.common.service.RabbitService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@EnableScheduling
@Slf4j
@Component
public class ScheduledTask {

    @Autowired
    private RabbitService rabbitService;

    //  定时任务的格式
//    @Scheduled(cron = "0/10 * * * * ?")
//    public void testTask(){
//        log.info("我是如何做到----不想听课，就想睡觉的呢?");
//        //  查询数据库 --- 将商品放入redis中.
//        //  System.out.println("呵呵");
//        rabbitService.sendMsg(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_1,"不想听课，就想睡觉! 我自豪，我骄傲!");
//    }

    //    @XxlJob("demoJobHandler")
    //    public void testTask(){
    //        log.info("我是如何做到----不想听课，就想睡觉的呢?");
    //        //  查询数据库 --- 将商品放入redis中.
    //        //  System.out.println("呵呵");
    //        rabbitService.sendMsg(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_1,"不想听课，就想睡觉! 我自豪，我骄傲!");
    //    }
    @XxlJob("demo")
    public void demo(){
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("hello");
        //   rabbitService.sendMsg(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_1,"不想听课，就想睡觉! 我自豪，我骄傲!");
    }
    //  清空秒杀数据
//    @Scheduled(cron = "0/10 * * * * ?")
//    public void clearData(){
//        log.info("我是如何做到----不想听课，就想睡觉的呢?");
//        //  查询数据库 --- 将商品放入redis中.
//        //  System.out.println("呵呵");
//        rabbitService.sendMsg(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_18,"终于结束了!");
//    }
}
